package com.erp.auto.controller;

import com.ruoyi.auto.api.domain.ErpAutoSellerStoreConfig;
import com.erp.auto.service.ErpAutoSellerStoreConfigService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.DateUtils;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 自动化店铺配置
 *
 * @author WXX
 * @date 2023-12-27 19:22:13
 */
@RestController
@AllArgsConstructor
@RequestMapping("/kjerp/erpAutoSellerStoreConfig")
public class ErpAutoSellerStoreConfigController {

    private final ErpAutoSellerStoreConfigService erpAutoSellerStoreConfigService;

    /**
     * 根据userId获取自动化店铺
     *
     * @param userId   登录用户id
     * @param revision 0：自己店铺；1：关联店铺
     * @return
     */
    @GetMapping("/selectAutoStore")
    public R<Object> selectAutoStore(Long userId, Integer revision) {
        return erpAutoSellerStoreConfigService.selectAutoStore(userId, revision);
    }

    @GetMapping("/queryAutoStoreByStoreUserName")
    public R<Object> selectById(String storeUserName) {
        return erpAutoSellerStoreConfigService.queryAutoStoreByStoreUserName(storeUserName);
    }

    @GetMapping("/getList")
    public R<Object> getList(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             ErpAutoSellerStoreConfig config) {

        PageHelper.startPage(pageNum, pageSize);
        List<ErpAutoSellerStoreConfig> list = erpAutoSellerStoreConfigService.getList(config);
        PageInfo<ErpAutoSellerStoreConfig> pageInfo = new PageInfo<>(list);
        return R.ok(pageInfo);
    }

    @GetMapping("/getStoreListByUser")
    public R<Object> getStoreListByUser() {
        return erpAutoSellerStoreConfigService.getStoreListByUser();
    }

    @GetMapping("/updateStatusById")
    public R<Object> updateStatusById(@RequestParam("id") Long id) {
        int save = erpAutoSellerStoreConfigService.updateStatusById(id);
        if (save > 0) {
            return R.ok();
        }
        return R.fail();
    }

    /**
     * 设置自动提交开关
     *
     * @param id
     * @param type 0-关闭 1-开启
     * @return
     */
    @GetMapping("/setAutoSubmitStore")
    public R<Object> setAutoSubmitStore(@RequestParam("id") Long id, @RequestParam("type") Integer type) {
        return erpAutoSellerStoreConfigService.setAutoSubmitStore(id, type);
    }

    /**
     * 查看详情
     */
    @GetMapping("/selectById")
    public R<ErpAutoSellerStoreConfig> selectById(@RequestParam("id") Long id) {
        return R.ok(erpAutoSellerStoreConfigService.selectById(id));
    }

    /**
     * 保存
     */
    @PostMapping("/saveConfig")
    public R<Object> saveConfig(@RequestBody ErpAutoSellerStoreConfig config) {
        String save = erpAutoSellerStoreConfigService.saveConfig(config);
        if (save.equals("1")) {
            return R.ok();
        } else if (save.equals("0")) {
            return R.fail();
        }
        return R.fail(save);
    }

    /**
     * 删除
     */
    @DeleteMapping("/deleteConfigById")
    public R<Object> deleteConfigById(Long id) {
        int del = erpAutoSellerStoreConfigService.deleteConfigById(id);
        if (del > 0) {
            return R.ok();
        }
        return R.fail();
    }

    /**
     * 自动提交订单
     *
     * @param id
     * @return
     */
    @GetMapping("/autoSubmitForReview")
    public R<Object> autoSubmitForReview(Long id) {
        return erpAutoSellerStoreConfigService.autoSubmitForReview(id);
    }

    @GetMapping("/autoSubmitForReviewInnerAuth")
    public R<Object> autoSubmitForReviewInnerAuth() {
        return erpAutoSellerStoreConfigService.autoSubmitForReview(null);
    }

    /**
     * 检测自动化店铺授权
     */
    @GetMapping("/checkAutoStoreAuth")
    public R<Object> checkAutoStoreAuth(String id) {
        return erpAutoSellerStoreConfigService.checkAutoStoreAuth(id);
    }


    /**
     * 查询自动化店铺的storeUserName
     *
     * @return
     */
    @GetMapping("/queryAutoStoreUserName")
    public R<Object> queryAutoStoreUserName() {
        return erpAutoSellerStoreConfigService.queryAutoStoreUserName();
    }

    /**
     * 重设活动 全店铺
     */
    @GetMapping("/resetActivityAllStore")
    public R<Object> resetActivityAllStore() {
        return erpAutoSellerStoreConfigService.resetActivityAllStore();
    }

    /**
     * 重设活动 异常补充
     */
    @GetMapping("/supplementResetActivityError")
    public R<Object> supplementResetActivityError(String storeUserName, String activityId) {
        return erpAutoSellerStoreConfigService.supplementResetActivityError(storeUserName, activityId);
    }

    /**
     * 重设活动 新版补充
     */
    @GetMapping("/supplementResetActivityErrorZero")
    public R<Object> supplementResetActivityErrorZero() {
        return erpAutoSellerStoreConfigService.supplementResetActivityErrorZero();
    }

    /**
     * 重设活动 单店铺
     */
    @GetMapping("/resetActivityByStoreUserName")
    public R<Object> resetActivityByStoreUserName(String storeUserName) {
        return erpAutoSellerStoreConfigService.resetActivityByStoreUserName(storeUserName);
    }

}
